package com.wdy.po;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.apache.struts2.util.StrutsTypeConverter;
@SuppressWarnings("unchecked")
public class TenementConverter extends StrutsTypeConverter {

	@Override
	public Object convertFromString(Map context, String[] values, Class toClass) {
		Set<Tenement> result = new HashSet();
		for(String str : values){
			Integer tid = Integer.parseInt(str);
			Tenement tenement = new Tenement();
			tenement.setTid(tid);
			result.add(tenement);
		}
		return result;
	}

	@Override
	public String convertToString(Map context, Object o) {
		if(o instanceof Set){
			Set<Tenement> set = (Set<Tenement>)o;
			String result = "[";
			for(Tenement t: set){
				result += "<" + t.getTid() + "," + t.getTname() + "> ";
			}
			result += "]";
			return result;
		}else{
			return "";
		}
		
	}

}
